

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.ico">
  <link rel="icon" href="/img/favicon.ico">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="Try not to become a man of success but rather try to become a man of value. ">
  <meta name="author" content="kinzun">
  <meta name="keywords" content>
  <meta name="description" content="报错123456789101112131415161718192021222324252627282930313233343536def chufa(a,b):    try: #尝试执行XX代码        ret = a/b #如果这里出现了错误.异常.        #系统内部会产生一个异常对象. 系统会把这个错误抛出,        #抛出给调用方        return ret">
<meta name="keywords" content="Python">
<meta property="og:type" content="article">
<meta property="og:title" content="Python约束和异常处理,Md5,日志处理">
<meta property="og:url" content="https://kinzun.github.io/2018/09/27/ Python约束和异常处理,Md5,日志处理/index.html">
<meta property="og:site_name" content="kinzun">
<meta property="og:description" content="报错123456789101112131415161718192021222324252627282930313233343536def chufa(a,b):    try: #尝试执行XX代码        ret = a/b #如果这里出现了错误.异常.        #系统内部会产生一个异常对象. 系统会把这个错误抛出,        #抛出给调用方        return ret">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://kinzun.github.io/images/python/python_exception.png">
<meta property="og:updated_time" content="2018-10-23T11:48:21.673Z">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Python约束和异常处理,Md5,日志处理">
<meta name="twitter:description" content="报错123456789101112131415161718192021222324252627282930313233343536def chufa(a,b):    try: #尝试执行XX代码        ret = a/b #如果这里出现了错误.异常.        #系统内部会产生一个异常对象. 系统会把这个错误抛出,        #抛出给调用方        return ret">
<meta name="twitter:image" content="https://kinzun.github.io/images/python/python_exception.png">
  
  <title>Python约束和异常处理,Md5,日志处理 - kinzun</title>

  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css">


  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4/github-markdown.min.css">
  <link rel="stylesheet" href="/lib/hint/hint.min.css">

  
    
    
      
      <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10/styles/github-gist.min.css">
    
  

  
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css">
  


<!-- 主题依赖的图标库，不要自行修改 -->
<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">

<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">

<link rel="stylesheet" href="/css/main.css">

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"kinzun.github.io","root":"/","version":"1.8.12","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname"}},"search_path":"/local-search.xml"};
  </script>
  <script src="/js/utils.js"></script>
  <script src="/js/color-schema.js"></script>
</head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>kinzun</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="Python约束和异常处理,Md5,日志处理">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2018-09-27 08:38" pubdate>
        2018年9月27日 早上
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      6.5k 字
    </span>
  

  
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      20 分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Python约束和异常处理,Md5,日志处理</h1>
            
            <div class="markdown-body">
              <p><img src="/images/python/python_exception.png" srcset="/img/loading.gif" lazyload alt></p>
<h4 id="报错"><a href="#报错" class="headerlink" title="报错"></a>报错</h4><figure class="highlight python"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">chufa</span><span class="hljs-params">(a,b)</span>:</span><br>    <span class="hljs-keyword">try</span>: <span class="hljs-comment">#尝试执行XX代码</span><br>        ret = a/b <span class="hljs-comment">#如果这里出现了错误.异常.</span><br>        <span class="hljs-comment">#系统内部会产生一个异常对象. 系统会把这个错误抛出,</span><br>        <span class="hljs-comment">#抛出给调用方</span><br>        <span class="hljs-keyword">return</span> ret<br>    <span class="hljs-comment"># except ZeroDivisionError as e:</span><br>    <span class="hljs-comment">#except ZeroDivisionErro as e: # 内部产生的所有异常都会被捕获 #捕获的异常对象会交给e</span><br>    <span class="hljs-comment">#    print(e)</span><br>    <span class="hljs-comment">#    print("出错,0不能是除数")</span><br>    <span class="hljs-comment"># except FileExistsError as e:</span><br>    <span class="hljs-comment"># except StopIteration as e:</span><br>    <span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> e:<br>    <span class="hljs-comment">#except:   #同 except Exception #所有异常</span><br>        print(e)<br>        print(<span class="hljs-string">"出错了"</span>)<br><br>    <span class="hljs-keyword">else</span>: <span class="hljs-comment">#保护不抛出异常的代码,当try 中无异常的时候执行</span><br><br><br>    <span class="hljs-keyword">finally</span>: <span class="hljs-comment">#最好总会执行部分</span><br><br>    <span class="hljs-comment"># return a/b</span><br>ret = chufa(<span class="hljs-number">5</span>,<span class="hljs-number">0</span>)<br>print(ret)<br><br><br><span class="hljs-comment">#计算两个整数的加法</span><br><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">add</span><span class="hljs-params">(a, b)</span>:</span><br>    <span class="hljs-keyword">if</span> type(a)!=int <span class="hljs-keyword">or</span> type(b) != int:<br>        <span class="hljs-comment"># return</span><br>        <span class="hljs-comment"># return Exception</span><br>        <span class="hljs-keyword">raise</span> TypeError(<span class="hljs-string">"我这里只要int, 不要别的类型"</span>)<br>    <span class="hljs-keyword">return</span> a + b<br><br>add(<span class="hljs-number">123</span>, <span class="hljs-string">"abc"</span><br></code></pre></div></td></tr></table></figure>
<h4 id="自定义异常返回"><a href="#自定义异常返回" class="headerlink" title="自定义异常返回"></a>自定义异常返回</h4><figure class="highlight python"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs python"><br><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">GenderError</span><span class="hljs-params">(Exception)</span>:</span><br>    <span class="hljs-keyword">pass</span><br><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Person</span>:</span><br>    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self,name,gender)</span>:</span><br>        self.name = name<br>        self.gender = gender<br><br><br><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">xi</span><span class="hljs-params">(per)</span>:</span><br>    <span class="hljs-keyword">if</span> per.gender != <span class="hljs-string">'男'</span>:<br>        <span class="hljs-keyword">raise</span> GenderError(<span class="hljs-string">"这里是男澡堂"</span>)<br>    <span class="hljs-keyword">else</span>:<br>        print(<span class="hljs-string">"进去了"</span>)<br>p1 = Person(<span class="hljs-string">'tudou'</span>,<span class="hljs-string">"不详"</span>)<br>p2 = Person(<span class="hljs-string">'mantou'</span>,<span class="hljs-string">'男'</span>)<br><br><br><span class="hljs-keyword">import</span> traceback <span class="hljs-comment"># 导入模块</span><br><span class="hljs-keyword">try</span>:<br>    xi(p2)<br><span class="hljs-keyword">except</span> GenderError <span class="hljs-keyword">as</span> g:<br>    print(g)<br>    val = traceback.format_exc() <span class="hljs-comment">#获取堆栈信息</span><br>    print(val)<br></code></pre></div></td></tr></table></figure>
<h4 id="类的约束"><a href="#类的约束" class="headerlink" title="类的约束"></a>类的约束</h4><p>约束是对子类进行的约束。</p>
<ul>
<li>在父类中给出一个方法。 这个方法中什么都不写。 就抛异常。 <code>NotImplementError()</code></li>
<li>在子类中把上述的方法进行重写。</li>
<li>在子类中把上述的方法进行重写。</li>
</ul>
<ol>
<li><p>python中有两种办法来解决这样的问题.</p>
<blockquote>
<p>提取父类. 然后在父类中定义好方法. 在这个方法中什么都不用干. 就抛一个异常就可以了. 这样所有的子类都必须重写这个方法. 否则. 访问的时候就会报错.</p>
</blockquote>
</li>
</ol>
<figure class="highlight python"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs python"><br><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Base</span>:</span><br>    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">login</span><span class="hljs-params">(self)</span>:</span><br>        <span class="hljs-comment">#raise Exception("没有实现login方法")</span><br>        <span class="hljs-keyword">raise</span> NotImplementedError(<span class="hljs-string">"没有实现login方法"</span>) <span class="hljs-comment">#专业的写法</span><br>    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">kantie</span><span class="hljs-params">(self)</span>:</span><br>        <span class="hljs-keyword">raise</span> Gk(<span class="hljs-string">"没有看帖功能"</span>)<br><br><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Normal</span><span class="hljs-params">(Base)</span>:</span><br>    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">login</span><span class="hljs-params">(self)</span>:</span><br>        print(<span class="hljs-string">"普通人登录"</span>)<br><br> <span class="hljs-comment">## 李四写</span><br><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Menber</span><span class="hljs-params">(Base)</span>:</span><br>    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">l</span><span class="hljs-params">(self)</span>:</span><br>        print(<span class="hljs-string">"吧务登录"</span>)<br><br> <span class="hljs-comment">## 王八</span><br><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Admin</span><span class="hljs-params">(Base)</span>:</span><br>    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">login</span><span class="hljs-params">(self)</span>:</span><br>        print(<span class="hljs-string">"管理员登录"</span>)<br><br><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">login</span><span class="hljs-params">(obj)</span>:</span><br>    print(<span class="hljs-string">"产生验证码"</span>)<br>    obj.login()<br>    print(<span class="hljs-string">"进入主页"</span>)<br> <span class="hljs-comment">## 场景</span><br><br><br>n = Normal()<br>m = Menber()<br>a = Admin()<br><br>login(n)<br>login(m)<br>login(a)<br></code></pre></div></td></tr></table></figure>
<ol start="2">
<li><blockquote>
<p>使⽤用元类来描述父类. 在元类中给出一个抽象方法. 这样子类就不得不给出抽象方法的具体实现. 也可以起到约束的效果.</p>
</blockquote>
<p>python中编写⼀一个抽象类比较⿇麻烦. 需要引入abc模块中的ABCMeta和<br>abstractmethod这两个内容. 来我们看一个例例⼦子.</p>
</li>
</ol>
<figure class="highlight python"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs python"><br><br><span class="hljs-keyword">from</span> abc <span class="hljs-keyword">import</span> ABCMeta,abstractmethod<br><br><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Base</span><span class="hljs-params">(metaclass=ABCMeta)</span>:</span><br><span class="hljs-meta">    @abstractmethod</span><br>    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">login</span><span class="hljs-params">(self)</span>:</span><span class="hljs-keyword">pass</span><br><br><br><span class="hljs-comment"># 张三</span><br><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Normal</span><span class="hljs-params">(Base)</span>:</span><br>    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">login</span><span class="hljs-params">(self)</span>:</span><br>        print(<span class="hljs-string">"::普通人登陆"</span>)<br><br><span class="hljs-comment"># 李四</span><br><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Member</span><span class="hljs-params">(Base)</span>:</span><br>    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">login</span><span class="hljs-params">(self)</span>:</span><br>        print(<span class="hljs-string">"::吧务登陆"</span>)<br><br><span class="hljs-comment"># 王五</span><br><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Admin</span><span class="hljs-params">(Base)</span>:</span><br>    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">login</span><span class="hljs-params">(self)</span>:</span><br>        print(<span class="hljs-string">"::管理员登陆"</span>)<br><br><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">login</span><span class="hljs-params">(obj)</span>:</span><br>    print(<span class="hljs-string">"1.产生验证码"</span>)<br>    obj.login() <span class="hljs-comment"># 标准在这里.  必须由login</span><br>    print(<span class="hljs-string">"3.进入主页"</span>)<br><br><span class="hljs-comment"># 场景</span><br>n = Normal()<br>m = Member()<br>a = Admin()<br>login(n)<br>login(m)<br>login(a)<br></code></pre></div></td></tr></table></figure>
<p>​   </p>
<blockquote>
<p>总结: 约束. 其实就是⽗类对⼦类进行约束. 子类必须要写xxx方法. 在python中约束的</p>
</blockquote>
<p>方式和方法有两种:</p>
<ol>
<li>使用抽象类和抽象方法, 由于该方案来源是java和c#. 所以使用频率还是很少的</li>
<li>使用人为抛出异常的方案. 并且尽量量抛出的是NotImplementError. 这样比较专业, 而且错误比较明确.(推荐)</li>
</ol>
<h4 id="异常类型"><a href="#异常类型" class="headerlink" title="异常类型"></a>异常类型</h4><figure class="highlight python"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs python">AttributeError 试图访问一个对象没有的树形，比如foo.x，但是foo没有属性x<br>IOError 输入/输出异常；基本上是无法打开文件<br>ImportError 无法引入模块或包；基本上是路径问题或名称错误<br>IndentationError 语法错误（的子类） ；代码没有正确对齐<br>IndexError 下标索引超出序列边界，比如当x只有三个元素，却试图访问x[<span class="hljs-number">5</span>]<br>KeyError 试图访问字典里不存在的键<br>KeyboardInterrupt Ctrl+C被按下<br>NameError 使用一个还未被赋予对象的变量<br>SyntaxError Python代码非法，代码不能编译(个人认为这是语法错误，写错了）<br>TypeError 传入对象类型与要求的不符合<br>UnboundLocalError 试图访问一个还未被设置的局部变量，基本上是由于另有一个同名的全局变量，<br>导致你以为正在访问它<br>ValueError 传入一个调用者不期望的值，即使值的类型是正确的<br><br>常用异常<br></code></pre></div></td></tr></table></figure>
<p>Exception 万能异常</p>
<h4 id="异常处理"><a href="#异常处理" class="headerlink" title="异常处理"></a>异常处理</h4>   <figure class="highlight python"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs python"><br><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">chu</span><span class="hljs-params">(a, b)</span>:</span><br>	<span class="hljs-keyword">return</span> a/b<br>	ret = chu(<span class="hljs-number">10</span>, <span class="hljs-number">0</span>)<br>	print(ret)<br><br><span class="hljs-comment">###ZeroDivisionError: division by zero</span><br><br><br><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">chu</span><span class="hljs-params">(a, b)</span>:</span><br>	<span class="hljs-keyword">return</span> a/b<br><span class="hljs-keyword">try</span>:<br>	ret = chu(<span class="hljs-number">10</span>, <span class="hljs-number">0</span>)<br>	print(ret)<br><span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> e:<br>	print(<span class="hljs-string">"除数不不能是0"</span>)<br>结果:<br>除数不不能是<span class="hljs-number">0</span><br><br><br><br><span class="hljs-keyword">try</span>:<br>	print(<span class="hljs-string">"各种操作...."</span>)<br><span class="hljs-keyword">except</span> ZeroDivisionError <span class="hljs-keyword">as</span> e:<br>	print(<span class="hljs-string">"除数不不能是0"</span>)<br><span class="hljs-keyword">except</span> FileNotFoundError <span class="hljs-keyword">as</span> e:<br>	print(<span class="hljs-string">"⽂文件不不存在"</span>)<br><span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> e:<br>	print(<span class="hljs-string">"其他错误"</span>)<br></code></pre></div></td></tr></table></figure>
<h4 id="MD5"><a href="#MD5" class="headerlink" title="MD5"></a>MD5</h4><blockquote>
<p>MD5是一种不可逆的加密算法. 它是可靠的. 并且安全的. 在python中我们不需要手写<br>这一套算法. 只需要引入一个叫hashlib的模块就能搞定MD5的加密工作</p>
</blockquote>
<figure class="highlight python"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs python"><br><span class="hljs-comment">#引入模块</span><br><span class="hljs-keyword">import</span> hashlib<br><br><br><span class="hljs-comment">#1.创建一个md5对象</span><br>obj = hashlib.md5()<br><span class="hljs-comment">#obj = hashlib.md5(b"3I31") #加..</span><br><br><span class="hljs-comment">#2.把要加密的内容给md5</span><br>obj.update(<span class="hljs-string">"root"</span>.encode(<span class="hljs-string">"utf-8"</span>)) <span class="hljs-comment">#必须是字节</span><br><br><span class="hljs-comment"># 3.获取密文</span><br><br>val = obj.hexdigest()<br>print(val)<br><span class="hljs-keyword">import</span>  hashlib<br><br><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">my_md5</span><span class="hljs-params">(yal)</span>:</span><br>    obj = hashlib.md5()<br>    obj.update(yal.encode(<span class="hljs-string">"utf-8"</span>))<br>    val = obj.hexdigest()<br>    <span class="hljs-keyword">return</span> val<br><br><br><span class="hljs-comment">#注册的时候,用md5 进行加密,</span><br><br>name = input(<span class="hljs-string">"name"</span>)<br>passwd = input(<span class="hljs-string">"passwd"</span>)<br><br><span class="hljs-comment">#ps = my_md5(passwd)</span><br><br><span class="hljs-keyword">if</span> name == <span class="hljs-string">"man"</span> <span class="hljs-keyword">and</span> my_md5(passwd) == <span class="hljs-string">"63a9f0ea7bb98050796b649e85481845"</span>:<br>    print(<span class="hljs-string">'go'</span>)<br><span class="hljs-keyword">else</span>:<br>    print(<span class="hljs-string">"n"</span>)<br></code></pre></div></td></tr></table></figure>
<p>使用实例</p>
<figure class="highlight python"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs python"><br><span class="hljs-comment"># python 检测文件MD5值</span><br><span class="hljs-comment"># python version 2.6</span><br><br><span class="hljs-keyword">import</span> hashlib<br><span class="hljs-keyword">import</span> os<br><span class="hljs-keyword">import</span> sys<br><br><br><span class="hljs-comment"># 简单的测试一个字符串的MD5值</span><br><span class="hljs-keyword">import</span> hashlib<br><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">md5sum</span><span class="hljs-params">(obj)</span>:</span><br>    hash = hashlib.md5()<br>    hash.update(obj.encode(<span class="hljs-string">'utf-8'</span>))<br>    <span class="hljs-keyword">return</span> hash.hexdigest()<span class="hljs-comment">#字符</span><br><br><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">GetStrMd5</span><span class="hljs-params">(src)</span>:</span><br>    m0 = hashlib.md5()<br>    m0.update(src)<br>    print(m0.hexdigest())<br>    <span class="hljs-keyword">pass</span><br><br><br><span class="hljs-comment"># 大文件的MD5值</span><br><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">GetFileMd5</span><span class="hljs-params">(filename)</span>:</span><br>    <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> os.path.isfile(filename):<br>        <span class="hljs-keyword">return</span><br>    myhash = hashlib.md5()<br>    f = open(filename, <span class="hljs-string">'rb'</span>)<br>    <span class="hljs-keyword">while</span> <span class="hljs-keyword">True</span>:<br>        b = f.read(<span class="hljs-number">8096</span>)<br>        <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> b:<br>            <span class="hljs-keyword">break</span><br>        myhash.update(b)<br>    f.close()<br>    <span class="hljs-keyword">return</span> myhash.hexdigest()<br><br><br><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">CalcSha1</span><span class="hljs-params">(filepath)</span>:</span><br>    <span class="hljs-keyword">with</span> open(filepath, <span class="hljs-string">'rb'</span>) <span class="hljs-keyword">as</span> f:<br>        sha1obj = hashlib.sha1()<br>        sha1obj.update(f.read())<br>        hash = sha1obj.hexdigest()<br>        print(hash)<br>        <span class="hljs-keyword">return</span> hash<br><br><br><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">CalcMD5</span><span class="hljs-params">(filepath)</span>:</span><br>    <span class="hljs-keyword">with</span> open(filepath, <span class="hljs-string">'rb'</span>) <span class="hljs-keyword">as</span> f:<br>        md5obj = hashlib.md5()<br>        md5obj.update(f.read())<br>        hash = md5obj.hexdigest()<br>        print(hash)<br>        <span class="hljs-keyword">return</span> hash<br><br><br><span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">"__main__"</span>:<br>    <span class="hljs-keyword">if</span> len(sys.argv) == <span class="hljs-number">2</span>:<br>        hashfile = sys.argv[<span class="hljs-number">1</span>]<br>        <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> os.path.exists(hashfile):<br>            hashfile = os.path.join(os.path.dirname(__file__), hashfile)<br>            <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> os.path.exists(hashfile):<br>                print(<span class="hljs-string">"cannot found file"</span>)<br>            <span class="hljs-keyword">else</span>:<br>                CalcMD5(hashfile)<br>        <span class="hljs-keyword">else</span>:<br>            CalcMD5(hashfile)<br>            <span class="hljs-comment"># raw_input("pause")</span><br>    <span class="hljs-keyword">else</span>:<br>        print(<span class="hljs-string">"no filename"</span>)<br></code></pre></div></td></tr></table></figure>
<h4 id="日志处理"><a href="#日志处理" class="headerlink" title="日志处理"></a>日志处理</h4><ol>
<li>导入logging模块.</li>
<li>简单配置⼀一下logging</li>
<li>出现异常的时候(except). 向⽇日志⾥里里写错误信息.</li>
</ol>
<figure class="highlight python"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs python"><span class="hljs-keyword">import</span> logging<br><br>logging.basicConfig(filename=<span class="hljs-string">'app.log'</span>,<br>                    format=<span class="hljs-string">'%(asctime)s - %(name)s - %(levelname)s - %(module)s: %(message)s'</span>,<br>                    datefmt=<span class="hljs-string">'%Y-%m-%d %H:%M:%S'</span>,<br>                    level=<span class="hljs-number">40</span>)    <span class="hljs-comment"># level 设置级别. 当你的信息的级别&gt;=level的时候才会写入日志文件, 默认30</span><br><br><span class="hljs-comment"># CRITICAL = 50</span><br><span class="hljs-comment"># FATAL = CRITICAL</span><br><span class="hljs-comment"># ERROR = 40</span><br><span class="hljs-comment"># WARNING = 30</span><br><span class="hljs-comment"># WARN = WARNING</span><br><span class="hljs-comment"># INFO = 20</span><br><span class="hljs-comment"># DEBUG = 10</span><br><span class="hljs-comment"># NOTSET = 0</span><br><span class="hljs-comment"># 写日志</span><br><span class="hljs-comment"># logging.critical("我是critical")</span><br><span class="hljs-comment"># logging.error("我是error")</span><br><span class="hljs-comment"># logging.warning("我是警告")</span><br><span class="hljs-comment"># logging.info("我是基本信息")</span><br><span class="hljs-comment"># logging.debug("我是调试")</span><br><span class="hljs-comment"># logging.log(2, "我是自定义")</span><br><br><br><span class="hljs-keyword">import</span> traceback<br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">20</span>):<br>    <span class="hljs-keyword">try</span>:<br>        <span class="hljs-keyword">if</span> i % <span class="hljs-number">3</span> == <span class="hljs-number">0</span>:<br>            <span class="hljs-keyword">raise</span> FileNotFoundError(<span class="hljs-string">"我是FileNotFountException"</span>)<br>        <span class="hljs-keyword">elif</span> i % <span class="hljs-number">3</span> == <span class="hljs-number">1</span>:<br>            <span class="hljs-keyword">raise</span> StopIteration()<br>        <span class="hljs-keyword">elif</span> i % <span class="hljs-number">3</span> == <span class="hljs-number">2</span>:<br>            <span class="hljs-keyword">raise</span> KeyError()<br><br>    <span class="hljs-keyword">except</span> FileNotFoundError <span class="hljs-keyword">as</span> e:<br>        val = traceback.format_exc()  <span class="hljs-comment"># 获取堆栈信息</span><br>        logging.error(val)<br>    <span class="hljs-keyword">except</span> StopIteration <span class="hljs-keyword">as</span> e:<br>        val = traceback.format_exc()<br>        logging.error(val)<br>    <span class="hljs-keyword">except</span> KeyError <span class="hljs-keyword">as</span> e:<br>        val = traceback.format_exc()<br>        logging.error(val)<br>    <span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> e:<br>        val = traceback.format_exc()<br>        logging.error(val)<br></code></pre></div></td></tr></table></figure>
<h4 id="多文件日志处理"><a href="#多文件日志处理" class="headerlink" title="多文件日志处理"></a>多文件日志处理</h4><figure class="highlight python"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs python"><br><span class="hljs-comment"># 创建⼀个操作⽇志的对象logger（依赖FileHandler）</span><br>file_handler = logging.FileHandler(<span class="hljs-string">'l1.log'</span>, <span class="hljs-string">'a'</span>, encoding=<span class="hljs-string">'utf-8'</span>)<br><span class="hljs-comment"># 设置日志文件内容的格式</span><br>file_handler.setFormatter(logging.Formatter(fmt=<span class="hljs-string">"%(asctime)s - %(name)s - %(levelname)s -%(module)s: %(message)s"</span>))<br>logger1 = logging.Logger(<span class="hljs-string">'A'</span>, level=<span class="hljs-number">40</span>)<br>logger1.addHandler(file_handler)<br><span class="hljs-comment"># 记录日志</span><br>logger1.error(<span class="hljs-string">'我是A系统'</span>)<br><br><br><br><span class="hljs-comment"># 再创建⼀个操作⽇志的对象logger（依赖FileHandler）</span><br>file_handler2 = logging.FileHandler(<span class="hljs-string">'l2.log'</span>, <span class="hljs-string">'a'</span>, encoding=<span class="hljs-string">'utf-8'</span>)<br>file_handler2.setFormatter(logging.Formatter(fmt=<span class="hljs-string">"%(asctime)s - %(name)s -%(levelname)s -%(module)s: %(message)s"</span>))<br>logger2 = logging.Logger(<span class="hljs-string">'B'</span>, level=<span class="hljs-number">40</span>)<br>logger2.addHandler(file_handler2)<br><span class="hljs-comment"># 记录日志</span><br>logger2.error(<span class="hljs-string">'我是B系统'</span>)<br></code></pre></div></td></tr></table></figure>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/Python/">Python</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2018/09/27/Python类与类之间的关系(3)/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Python类与类之间的关系(3)</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2018/09/26/Python面对对象成员(2)/">
                        <span class="hidden-mobile">Python:面对对象成员(2)</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
              <!-- Comments -->
              <article class="comments" id="comments" lazyload>
                
                  
                
                

              </article>
            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  

  

  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  <script  src="/js/local-search.js" ></script>



  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  
    <script  src="https://cdn.jsdelivr.net/npm/tocbot@4/dist/tocbot.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4/anchor.min.js" ></script>
  
  
    <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js" ></script>
  






  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
      typing(title)
      
    })(window, document);
  </script>















<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


</body>
</html>
